import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'ButtonPage.dart';
import 'ContextRoutePage.dart';
import 'EchoWidgetPage.dart';
import 'StateLifeCirclePage.dart';
import 'SwitchAndCheckBoxPage.dart';
import 'TextFieldFormPage.dart';

class BaseWidgetPage extends StatelessWidget {
  final List<String> items = ['StatelessElement',
    'ContextRoutePage',
    'StateLifeCirclePage',
    '按钮',
    'SwitchAndCheckBoxPage',
    'TextFieldFormPage'
  ];

  BaseWidgetPage({Key key, this.title}) : super(key: key);
  final String title;

  getPage(BuildContext context, int index) {
//    print(">>>> tap  $index");
    switch (index) {

      case 0:
        return new EchoWidgetPage(title: items[index]);

        case 1:
        return new ContextRoutePage();

        case 2:
        return new StateLifeCirclePage(initValue: 3);
        case 3:
        return new ButtonPage();
        case 4:
        return new SwitchAndCheckBoxPage();
        case 5:
        return new TextFieldFormPage();
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text(title)),
        body: ListView.builder(
            padding: const EdgeInsets.all(10),
            itemCount: items.length,
            itemBuilder: (context, index) {
              return GestureDetector(
                child: Container(
                    height: 60, child: Center(child: Text(items[index]))),
                onTap: () {
                  var page = getPage(context, index);
                  print(page.toString());
                  Navigator.push(context, MaterialPageRoute(builder:(context){
                    return getPage(context,index);
                  }));
                },
              );
            }));
  }
}
